// 云函数入口文件
const cloud = require('wx-server-sdk');

cloud.init({ env: cloud.DYNAMIC_CURRENT_ENV });

// 云函数入口函数
exports.main = async (event, context) => {
  try {
    const db = cloud.database();
    const userInfoCollection = db.collection('userInfo');
    const userInfoList = await userInfoCollection.get();

    return {
      code: 0,
      data: userInfoList.data,
    };
  } catch (error) {
    return {
      code: -1,
      msg: '获取数据失败',
      error: error,
    };
  }
};
